<script setup>
import uniIdPageInit from "@/uni_modules/uni-id-pages/init.js";
import { onHide, onLaunch, onShow } from "@dcloudio/uni-app";
import { useUserStore } from "@/store/user";

const userStore = useUserStore();

const uniIdCo = uniCloud.importObject("uni-id-co");

onLaunch(async () => {
	console.log("App Launch");
	await uniIdPageInit();

	uni.$on("uni-id-pages-login-success", async (event) => {
		userStore.setIsLogin(true);
		await userStore.fetchGetAccountInfo();
	});

	uni.$on("uni-id-pages-logout", (event) => {
		console.log("logout");
		userStore.setIsLogin(false);
		uni.clearStorageSync();
	});

	console.log(`isLogin:${userStore.isLogin}`);
	if (!userStore.isLogin) {
		uni.reLaunch({
			url: "/uni_modules/uni-id-pages/pages/login/login-withpwd"
		});
	} else {
		userStore.fetchGetAccountInfo();
	}
});

onShow(() => {
	console.log("onShow");
});

onHide(() => {
	console.log("onHide");
});
</script>

<style lang="scss">
@import url("./static/styles/global.scss");
</style>
